package fr.cpe.dp.projet2.model.musicBuilder;

import javax.sound.midi.MidiEvent;
import javax.sound.midi.Sequence;
import javax.sound.midi.Track;
import javax.sound.midi.InvalidMidiDataException;
import java.util.logging.Logger;
import java.util.logging.Level;

/**
 *
 * @author Benoit
 */
public class RangeBuilder extends AbstractMusicBuilder {

    @Override
    public Sequence generateSequence() {
	    	Sequence seq = null;
	        try {
	            seq = new Sequence(Sequence.PPQ, 4);
	            Track piste = seq.createTrack();
	            int note = 63;
	            for (int i = 0; i <= 15; i += 2) {
	            	note += 2;
	                piste.add(makeEvent(144, 1, note, 100, i));
	                piste.add(makeEvent(176, 1, 127, 0, i));
	                piste.add(makeEvent(128, 1, note, 100, i + 1));
	            }

	            for (int i = 15; i <= 30; i += 1) {
	            	note -= 2;
	                piste.add(makeEvent(144, 1, note, 100, i));
	                piste.add(makeEvent(176, 1, 127, 0, i));
	                piste.add(makeEvent(128, 1, note, 100, i + 2));
	            }
	        } catch (InvalidMidiDataException ex) {
	            Logger.getLogger(RandomBuilder.class.getName()).log(Level.SEVERE, null, ex);
	        }
        	return seq;
        }
    
}
